﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    public class BestOfPopulationChildrenReplacement : Replacement
    {
        public List<bool[]> prev, curr;
        public double[] prev_objective, curr_objective;
        List<Pair<int, double>> full_list;

        public BestOfPopulationChildrenReplacement(List<bool[]> prev, List<bool[]> curr, double[] prev_objective, double[] curr_objective)
        {
            this.curr = curr;
            this.prev = prev;
            this.curr_objective = curr_objective;
            this.prev_objective = prev_objective;

            full_list = new List<Pair<int, double>>();

            for (int i = 0; i < prev.Count; i++)
            {
                full_list.Add(new Pair<int, double>(i, prev_objective[i]));
            }

            for (int i = prev.Count; i < prev.Count + curr.Count; i++)
            {
                full_list.Add(new Pair<int, double>(i, curr_objective[i - prev.Count]));
            }
        }

        public override List<bool[]> returnNewGeneration()
        {
            List<bool[]> result = new List<bool[]>();
            // sortowanie ...
            full_list = full_list.OrderByDescending(x => x.Second).ToList();

            for (int i = 0; i < prev.Count; i++)
            {
                if (full_list[i].First < prev.Count)
                    result.Add(prev[full_list[i].First]);
                else
                    result.Add(curr[full_list[i].First-prev.Count]); 
            }

            return result;
        }
    }
}
